package com.zxjia.ssmp.controller;

import com.zxjia.ssmp.dto.ProductRequest;
import com.zxjia.ssmp.service.ProductService;
import com.zxjia.ssmp.vo.Result;
import com.zxjia.ssmp.vo.ProductCateVo;
import com.zxjia.ssmp.vo.ProductVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Api(tags = "商品信息管理")
@RestController
@RequestMapping(value = "/api/product")
public class ProductController {

    @Autowired
    ProductService productService;

    @ApiOperation(value = "查询商品类别信息")
    @PostMapping(value = "/cate/list")
    public Result<List<ProductCateVo>> list() {
        return Result.success(productService.list());
    }

    @ApiOperation(value = "查询商品类别信息")
    @PostMapping(value = "/cate/getProductByCateId")
    public Result<List<ProductVo>> getProductByCateId(@RequestBody ProductRequest request) {
        return Result.success(productService.getProductByCateId(request));
    }

    @ApiImplicitParam(name = "productId",value = "商品id",required = true)
    @ApiOperation(value = "商品详情")
    @GetMapping(value = "/getProductById")
    public Result<ProductVo> getProductById(ProductRequest request) {
        return Result.success(productService.getProductById(request));
    }
}
